const { OrderStatus } = require('../constants/DbEnum');

/**
 * Order History DTO
 */
class OrderHistoryDto extends Array {
  /**
   * constructor
   * @param {Array<Order>} orders
   */
  constructor(orders) {
    super();
    for (const order of orders) {
      if (order.status == OrderStatus.PENDING && order.Trades.length == 0) {
        continue;
      }

      this.push(this._buildOrder(order.get()));
    }
  }

  /**
   * build order item
   * @param {Order} order
   * @return {Object<item>} item
   * @private
   */
  _buildOrder(order) {
    delete order.buyTrades;
    delete order.sellTrades;

    return order;
  }
}

module.exports = OrderHistoryDto;
